home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1999 #2 / Amiga Plus CD - 1999 - No. 2.iso / System-Boost / Workbench / TinyMeter / Source / TinyMeter_main / gaugeclass.c < prev    next >
C/C++ Source or Header  |  1997-02-27  |  26KB  |  980 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <dos/dos.h>
  4. #include <proto/SysInfo.h>
  5. #include <libraries/SysInfo.h>
  6. #include <dos/dosextens.h>
  7. #include <intuition/intuition.h>
  8. #include <intuition/gadgetclass.h>
  9. #include <intuition/intuitionbase.h>
  10. #include <intuition/classusr.h>
  11. #include <intuition/imageclass.h>
  12. #include <intuition/gadgetclass.h>
  13. #include <intuition/cghooks.h>
  14. #include <intuition/icclass.h>
  15. #include <intuition/classes.h>
  16. #include <intuition/sghooks.h>
  17. #include <intuition/screens.h>
  18. #include <graphics/gfxbase.h>
  19. #include <graphics/text.h>
  20. #include <graphics/gfxmacros.h>
  21. #include <utility/tagitem.h>
  22. #include <utility/hooks.h>
  23. #include <string.h>
  24. #include "gaugeclass.h"
  25. #include "tinymeter.h"
  26.  
  27. struct GaugeData
  28. {
  29.     ULONG   min;
  30.     ULONG   max;
  31.     ULONG   current;
  32.     ULONG   base;
  33.     ULONG   old_cur;
  34.     ULONG   old_bas;
  35.     WORD    labelpos;
  36.     UBYTE   fmtind;
  37.  
  38.     ULONG   type, diswhat;
  39.  
  40.     char    *txtlbl;
  41.     char    *txtfmt;
  42.  
  43.     struct  GAU_Color Colors[GAU_UsedColors];
  44.  
  45.     BOOL    Style3D;
  46.     BOOL    StyleBorder;
  47.     BOOL    StyleBackground;
  48.     BOOL    StyleShadowLabel;
  49.     BOOL    StyleNoGauge;
  50.     BOOL    StyleNoFormat;
  51.     BOOL    StyleNoBase;
  52.  
  53.     struct  TextFont *textFont;
  54.  
  55.     ULONG   Pens[GAU_UsedColors];
  56.     BOOL    PorC[GAU_UsedColors];
  57.  
  58.     BOOL    InitNotDone;
  59.  
  60.     struct  RastPort *nolock_rp;
  61.  
  62.     LONG    histpos,
  63.         oldlgth,
  64.         oldx;
  65.  
  66.     WORD    text_y;
  67.     struct  Locale *locale;
  68.     char    clocktxt[256];
  69.     char    *voltxt;
  70.  
  71.     struct  RastPort   *bg_buffer;
  72.     struct  RastPort   *wk_buffer;
  73.     struct  RastPort   *hs_buffer;
  74.  
  75.     WORD    clockpos;
  76.  
  77.     BOOL    highlight;
  78.     WORD    oldclockx;
  79.     WORD    oldclockw;
  80.  
  81.     ULONG   voltype;
  82.     struct  Screen *scr;
  83. };
  84.  
  85.  
  86. extern struct SysInfo *si;
  87. extern ULONG           executive;
  88. extern struct Library *RetinaBase;
  89. extern ULONG  idle, maximum;
  90.  
  91. __saveds ULONG dispatchGaugeGadget(Class *cl,Object *o, Msg msg)
  92. {
  93.     switch( msg->MethodID )
  94.     {
  95.     case    OM_SET:
  96.         setGauge(cl,(struct Gadget *)o,(struct gpRender *)msg);
  97.         return(DoSuperMethodA(cl,o,msg));
  98.     case    GM_RENDER:
  99.         return(renderGauge(cl,(struct Gadget *)o,(struct gpRender *)msg));
  100.     case    OM_NEW:
  101.         if(o = (Object *)DoSuperMethodA(cl, o, msg) )
  102.              return(newGauge(cl,(struct Gadget *)o,(struct gpRender *)msg,INST_DATA(cl, o)));
  103.         else return(0L);
  104.     case    OM_GET:
  105.         return(getGauge(cl,(struct Gadget *)o,(struct gpRender *)msg));
  106.     case    MY_REFRESH:
  107.         my_Refresh(cl,(struct Gadget *)o,msg);
  108.         return(0L);
  109.     case    OM_DISPOSE:
  110.         disposeGauge(cl,(struct Gadget *)o,(struct gpRender *)msg);
  111.     default:
  112.         return(DoSuperMethodA(cl,o,msg));
  113.     }
  114. }
  115.  
  116. Class *initGaugeGadgetClass(void)
  117. {
  118.     struct IClass *cl;
  119.     if( cl = (struct IClass *)MakeClass( NULL, "gadgetclass", NULL, sizeof(struct GaugeData), 0) )
  120.     {  
  121.     cl->cl_Dispatcher.h_Entry    = HookEntry;
  122.     cl->cl_Dispatcher.h_SubEntry = (HOOKFUNC)dispatchGaugeGadget;
  123.     return((Class *)cl);
  124.     }
  125.     return(0L);
  126. }
  127.  
  128. BOOL freeGaugeGadgetClass( Class *cl )
  129. {
  130.     return(FreeClass(cl));
  131. }
  132.  
  133. void getVolsize(struct GaugeData *inst,char *volname)
  134. {
  135.     struct InfoData  inf;
  136.     struct DevProc  *devproc;
  137.     if(devproc=(struct DevProc *)GetDeviceProc(volname,NULL))
  138.     {
  139.     if(DoPkt(devproc->dvp_Port,ACTION_DISK_INFO,MKBADDR(&inf),NULL,NULL,NULL,NULL)==DOSTRUE)
  140.     {
  141.         switch(inf.id_DiskType)
  142.         {
  143.         case    0x42555359:
  144.             inst->max    =0;
  145.             inst->current=GAU_err_busy;
  146.             break;
  147.         case    ID_UNREADABLE_DISK:
  148.             inst->max    =0;
  149.             inst->current=GAU_err_unreadable;
  150.             break;
  151.         case    ID_NOT_REALLY_DOS:
  152.             inst->max    =0;
  153.             inst->current=GAU_err_nodos;
  154.             break;
  155.         case    ID_NO_DISK_PRESENT:
  156.             inst->max    =0;
  157.             inst->current=GAU_err_notpresent;
  158.             break;
  159.         case    ID_KICKSTART_DISK:
  160.             inst->max    =0L;
  161.             inst->current=GAU_err_kickstart;
  162.             break;
  163.         default:
  164.             inst->current=(inf.id_NumBlocks-inf.id_NumBlocksUsed)*inf.id_BytesPerBlock;
  165.             inst->max    =inf.id_NumBlocks*inf.id_BytesPerBlock;
  166.             inst->voltype=inf.id_DiskType;
  167.             break;
  168.         }
  169.     }
  170.     FreeDeviceProc(devproc);
  171.     }
  172.     else
  173.     {
  174.     inst->max=0;
  175.     inst->current=GAU_err_notmount;
  176.     }
  177. }
  178.  
  179. void my_Refresh(Class *cl,struct Gadget *g,Msg msg)
  180. {
  181.     struct  GaugeData *inst=INST_DATA(cl,g);
  182.  
  183.     switch (inst->diswhat)
  184.     {
  185.     case    typ_all:
  186.         inst->current=AvailMem(0L);
  187.         break;
  188.     case    typ_chip:
  189.         inst->current=AvailMem(MEMF_CHIP);
  190.         break;
  191.     case    typ_fast:
  192.         inst->current=AvailMem(MEMF_FAST);
  193.         break;
  194.     case    typ_idle:
  195.         switch (executive)
  196.         {
  197.             case    idle_none:
  198.                 inst->current=0L;
  199.                 break;
  200.             case    idle_executive:
  201.                 {
  202.                 struct SI_CpuUsage  cpu;
  203.                 GetCpuUsage(si,&cpu);
  204.                 inst->current=(cpu.used_cputime_lastsec_hz-cpu.used_cputime_lastsec)<<8;
  205.                 }
  206.                 break;
  207.             case    idle_own:
  208.                 inst->current=idle;
  209.                 break;
  210.         }
  211.         if(inst->base<inst->current)inst->base=inst->current;
  212.         break;
  213.     case    typ_largest_total:
  214.         inst->current=AvailMem(MEMF_LARGEST);
  215.         break;
  216.     case    typ_largest_chip:
  217.         inst->current=AvailMem(MEMF_LARGEST|MEMF_CHIP);
  218.         break;
  219.     case    typ_largest_fast:
  220.         inst->current=AvailMem(MEMF_LARGEST|MEMF_FAST);
  221.         break;
  222.     case    typ_largest_retina:
  223.         if(RetinaBase)
  224.             inst->current=Retina_AvailMem(MEMF_LARGEST);
  225.         else
  226.             inst->current=GAU_err_notavail;
  227.         break;
  228.     case    typ_retina:
  229.         if(RetinaBase)
  230.             inst->current=Retina_AvailMem(0L);
  231.         else
  232.             inst->current=GAU_err_notavail;
  233.         break;
  234.     case    typ_volume:
  235.         if(inst->voltxt)getVolsize(inst,inst->voltxt);
  236.         break;
  237.     default:
  238.         break;
  239.     }
  240.     if(msg) renderGauge(cl,g,(struct gpRender *)msg);
  241. }
  242.  
  243. void my_Max(Class *cl,struct Gadget *g)
  244. {
  245.     struct  GaugeData *inst=INST_DATA(cl,g);
  246.     switch (inst->diswhat)
  247.     {
  248.     case    typ_largest_total:
  249.     case    typ_all:
  250.         inst->max=AvailMem(MEMF_TOTAL);
  251.         break;
  252.     case    typ_largest_chip:
  253.     case    typ_chip:
  254.         inst->max=AvailMem(MEMF_CHIP|MEMF_TOTAL);
  255.         break;
  256.     case    typ_largest_fast:
  257.     case    typ_fast:
  258.         inst->max=AvailMem(MEMF_FAST|MEMF_TOTAL);
  259.         break;
  260.     case    typ_idle:
  261.         switch (executive)
  262.         {
  263.             case    idle_none:
  264.                 inst->max=0L;
  265.                 break;
  266.             case    idle_executive:
  267.                 {
  268.                 struct SI_CpuUsage  cpu;
  269.                 GetCpuUsage(si,&cpu);
  270.                 inst->max=(cpu.used_cputime_lastsec_hz)<<8;
  271.                 }
  272.                 break;
  273.             case    idle_own:
  274.                 inst->max=maximum;
  275.                 break;
  276.         }
  277.         break;
  278.     case    typ_largest_retina:
  279.     case    typ_retina:
  280.         if(RetinaBase)
  281.             inst->max=Retina_AvailMem(MEMF_TOTAL);
  282.         else
  283.             inst->max=GAU_err_notavail;
  284.         break;
  285.     default:
  286.         break;
  287.     }
  288.     inst->base=inst->current;
  289. }
  290.  
  291.  
  292. ULONG newGauge(Class *cl,struct Gadget *g,struct gpRender *msg,struct GaugeData *inst)
  293. {
  294.     struct   TagItem *ti;
  295.     if(ti = ((struct opSet *)msg)->ops_AttrList)
  296.     {
  297.     if(inst->textFont = (struct TextFont *)GetTagData(GAU_TextFont,(ULONG)OpenTopaz(),ti))
  298.     {
  299.         struct RastPort *dummy;
  300.         if(dummy=(struct RastPort *)pAllocVec(sizeof(struct RastPort)))
  301.         {
  302.         int     i;
  303.         char    *foo;
  304.         UWORD   def_pens[]={ 2, 2, 1, 3, 1, 2, 1, 0 };
  305.         ULONG   gau_tags[]={GAU_ColLabel,GAU_ColFormat,GAU_ColBase,GAU_ColCurrent,GAU_ColNegative,GAU_ColBrightEdg,GAU_ColDarkEdg,GAU_ColBackground};
  306.  
  307.         InitRastPort(dummy);
  308.         dummy->Font=inst->textFont;
  309.  
  310.         inst->txtfmt            = (char *)GetTagData(GAU_TextFormat,(ULONG)"%td",ti);
  311.         inst->txtlbl            = (char *)GetTagData(GAU_Label,(ULONG)"Gauge", ti);
  312.         inst->labelpos          = GetTagData(GAU_LabelPos,TextLength(dummy,inst->txtlbl,my_strlen(inst->txtlbl))+4, ti);
  313.  
  314.         inst->Style3D           = GetTagData(GAU_3D,  TRUE, ti);
  315.         inst->StyleBorder       = GetTagData(GAU_Border, TRUE, ti);
  316.         inst->StyleBackground   = GetTagData(GAU_Background, FALSE, ti);
  317.         inst->StyleShadowLabel  = GetTagData(GAU_ShadowLabel, FALSE, ti);
  318.         inst->StyleNoGauge      = GetTagData(GAU_NoGauge,   FALSE, ti);
  319.         inst->StyleNoFormat     = GetTagData(GAU_NoFormat,  FALSE, ti);
  320.         inst->StyleNoBase       = GetTagData(GAU_NoBase,  FALSE, ti);
  321.         inst->fmtind            = GetTagData(GAU_FmtIndent, FALSE, ti);
  322.         inst->type              = GetTagData(GAU_Type, GAU_Type_gauge, ti);
  323.         inst->diswhat           = GetTagData(GAU_DisWhat, 0,ti);
  324.         inst->voltxt=0L;
  325.         if(foo                  = (char *)GetTagData(GAU_Expansion,NULL,ti))
  326.         {
  327.             if(inst->diswhat==typ_volume)
  328.             {
  329.             inst->voltxt=foo;
  330.             }                    
  331.         }
  332.         for(i=0;i<GAU_UsedColors;i++) CopyMem((APTR)GetTagData(gau_tags[i],(ULONG)GetGaugePen(def_pens[i]),ti),(APTR)&inst->Colors[i],sizeof(struct GAU_Color));
  333.  
  334.         if(inst->diswhat==typ_clock_)
  335.         {
  336.             inst->type      = typ_clock;
  337.             inst->locale    = (struct Locale *)OpenLocale(NULL);
  338.         }
  339.         else inst->locale   = 0L;
  340.  
  341.         inst->InitNotDone=TRUE;
  342.         inst->highlight=TRUE;
  343.         inst->oldclockw=0L;
  344.         inst->oldclockx=0L;
  345.  
  346.         pFreeVec((ULONG *)dummy);
  347.  
  348.         my_Refresh(cl,g,NULL);
  349.         my_Max(cl,g);
  350.  
  351.         return((ULONG)g);
  352.         }
  353.         else return(0L);
  354.     }
  355.     else return(0L);
  356.     }
  357.     else return(0L);
  358. }
  359.  
  360. void freeRPorts(struct GaugeData *inst)
  361. {
  362.     if(inst->bg_buffer)
  363.     {
  364.     FreeBitMap(inst->bg_buffer->BitMap);
  365.     pFreeVec((ULONG *)inst->bg_buffer);
  366.     inst->bg_buffer=0L;
  367.     }
  368.  
  369.     if(inst->wk_buffer)
  370.     {
  371.     FreeBitMap(inst->wk_buffer->BitMap);
  372.     pFreeVec((ULONG *)inst->wk_buffer);
  373.     inst->wk_buffer=0L;
  374.     }
  375.  
  376.     if(inst->hs_buffer)
  377.     {
  378.     FreeBitMap(inst->hs_buffer->BitMap);
  379.     pFreeVec((ULONG *)inst->hs_buffer);
  380.     inst->hs_buffer=0L;
  381.     }
  382.  
  383. }
  384.  
  385. void disposeGauge(Class *cl,struct Gadget *g,struct gpRender *msg)
  386. {
  387.     int w;
  388.     struct GaugeData *inst=INST_DATA(cl,g);
  389.     CloseLocale(inst->locale);
  390.     for(w=0;w<GAU_UsedColors;w++)FreePenNew(inst->scr,&inst->Colors[w],w,inst->Pens);
  391.     freeRPorts(inst);
  392. }
  393.  
  394. ULONG getGauge(Class *cl,struct Gadget *g,struct gpRender *msg)
  395. {
  396.     struct GaugeData *inst=INST_DATA(cl,g);
  397.     switch (((struct opGet *)msg)->opg_AttrID)
  398.     {
  399.     case    GAU_RPBackground:
  400.         *(((struct opGet *)msg)->opg_Storage)=(ULONG)inst->bg_buffer;
  401.         break;
  402.     case    GAU_Base:
  403.         *(((struct opGet *)msg)->opg_Storage)=(ULONG)inst->base;
  404.         break;
  405.     case    GAU_Current:
  406.         *(((struct opGet *)msg)->opg_Storage)=(ULONG)inst->current;
  407.         break;
  408.     default:
  409.         *(((struct opGet *)msg)->opg_Storage)=0L;
  410.         break;
  411.     }
  412.     return((ULONG)TRUE);
  413. }
  414.  
  415. void setGauge(Class *cl,struct Gadget *g,struct gpRender *msg)
  416. {
  417.     struct TagItem      *ti,*tstate=((struct opSet *)msg)->ops_AttrList;
  418.     struct GaugeData    *inst=INST_DATA(cl,g);
  419.     ULONG  t_data;
  420.  
  421.     while(ti=(struct TagItem *)NextTagItem(&tstate))
  422.     {
  423.     t_data=(ULONG)ti->ti_Data;
  424.     switch(ti->ti_Tag)
  425.     {
  426.         case    GAU_Current:
  427.             inst->current=  (ULONG)t_data;
  428.             break;
  429.         case    GAU_Base:
  430.             inst->base=     (ULONG)t_data;
  431.             break;
  432.         case    GAU_Max:
  433.             inst->max=      (ULONG)t_data;
  434.             break;
  435.         case    GAU_VolType:
  436.             inst->voltype=  (ULONG)t_data;
  437.             break;
  438.     }
  439.     }
  440.     if ( FindTagItem(GA_Width,  ((struct opSet *)msg)->ops_AttrList) ||
  441.      FindTagItem(GA_Height, ((struct opSet *)msg)->ops_AttrList) ||
  442.      FindTagItem(GA_Top,    ((struct opSet *)msg)->ops_AttrList) ||
  443.      FindTagItem(GA_Left,   ((struct opSet *)msg)->ops_AttrList) )
  444.     {
  445.     inst->highlight=TRUE;
  446.     inst->InitNotDone=TRUE;
  447.     freeRPorts(inst);
  448.     }
  449. }
  450.  
  451. char *formattext(ULONG current, ULONG base, ULONG max, char format[], ULONG special, char *temp_str)
  452. {
  453.     int         i=0,
  454.         j=0;
  455.     char        temp_str_1[64];
  456.     BOOL        negative;
  457.  
  458.     while(format[i]!=0)
  459.     {
  460.     if(format[i]=='%')
  461.     {
  462.         ULONG   dummy=0;
  463.         UBYTE   dummy_2=0,
  464.             dummy_1=0,
  465.             dummy_3=0;
  466.         i++;
  467.         if(format[i]=='t'){dummy_2=1;i++;}
  468.         if(format[i]=='T'){dummy_2=4;i++;}
  469.         if(format[i]=='k'){dummy_1=1;i++;}
  470.         if(format[i]=='m'){dummy_1=2;i++;}
  471.         if(format[i]=='o'){dummy_3=1;i++;}
  472.         if(format[i]=='%'){dummy_2=3;i++;}
  473.         switch(format[i])
  474.         {
  475.         case    'd':
  476.             dummy=current;
  477.             negative=FALSE;
  478.             break;
  479.         case    'b':
  480.             dummy=base;
  481.             negative=FALSE;
  482.             break;
  483.         case    'f':
  484.             dummy   = base<current ? current-base   : base-current;
  485.             negative= base<current ? TRUE           : FALSE;
  486.             break;
  487.         case    'a':
  488.             dummy=max;
  489.             negative=FALSE;
  490.             break;
  491.         case    'p':
  492.             dummy_2=2; dummy=current;
  493.             negative=FALSE;
  494.             break;
  495.         case    'v':
  496.             dummy_2=5;
  497.             break;
  498.         default:
  499.             goto noforward;
  500.             break;
  501.         }
  502.         i++;
  503. noforward:
  504.         if(dummy_3==1)dummy=max-dummy;
  505.         if(dummy_1==1)dummy=dummy>>10;
  506.         if(dummy_1==2)dummy=dummy>>20;
  507.         switch(dummy_2)
  508.         {
  509.         case    4:
  510.             dummy_2=long_2_string_with_thousand(dummy,&temp_str_1[0],'.',negative);
  511.             for(dummy_1=0;dummy_1<dummy_2;dummy_1++) temp_str[j++]=temp_str_1[dummy_1];
  512.             break;
  513.         case    1:
  514.             dummy_2=long_2_string_with_thousand(dummy,&temp_str_1[0],',',negative);
  515.             for(dummy_1=0;dummy_1<dummy_2;dummy_1++) temp_str[j++]=temp_str_1[dummy_1];
  516.             break;
  517.         case    2:
  518.             dummy_2=0;
  519.             if(negative) sprintf(&temp_str_1[0],"-%ld",(((dummy>>8)*100)/((max>>8)+1)));
  520.             else         sprintf(&temp_str_1[0],"%ld", (((dummy>>8)*100)/((max>>8)+1)));
  521.             while ((temp_str_1[dummy_2] != 0)&(dummy_2<64)) temp_str[j++]=temp_str_1[dummy_2++];
  522.             break;
  523.         case    0:
  524.             dummy_2=0;
  525.             if(negative) sprintf(&temp_str_1[0],"-%ld",dummy);
  526.             else         sprintf(&temp_str_1[0],"%ld", dummy);
  527.             while ((temp_str_1[dummy_2] != 0)&(dummy_2<64)) temp_str[j++]=temp_str_1[dummy_2++];
  528.             break;
  529.         case    3:
  530.             temp_str[j++]='%';
  531.             break;
  532.         case    5:
  533.             if(special&0xFF000000)temp_str[j++]=(char)((special>>24)&0xFF);
  534.             if(special&0x00FF0000)temp_str[j++]=(char)((special>>16)&0xFF);
  535.             if(special&0x0000FF00)temp_str[j++]=(char)((special>>8) &0xFF);
  536.             temp_str[j++]='\\';
  537.             temp_str[j++]=(char)( special     &0xFF)+0x30;
  538.             break;
  539.         }
  540.     }
  541.     else temp_str[j++]=format[i++];
  542.     }
  543.     temp_str[j]=0;
  544.     return(temp_str);
  545. }
  546.  
  547. __saveds void putChar_hook(struct Hook *hook,struct Locale *locale,ULONG thechar)
  548. {
  549.     struct GaugeData *data;
  550.     data=(struct GaugeData *)hook->h_Data;
  551.     data->clocktxt[data->clockpos++]=(UBYTE)(thechar);
  552. }
  553.  
  554. struct Hook putCharHook = { { 0,0 },(void *)HookEntry,(void *)putChar_hook, NULL };
  555.  
  556. char *getSTR(struct GaugeData *inst)
  557. {
  558.     static char *errstr[]=
  559.     {
  560.     "Disk is busy",
  561.     "Not mounted",
  562.     "No disk present",
  563.     "Disk unreadable",
  564.     "No DOS format",
  565.     "n.a.",
  566.     "Kickstart disk"
  567.     };
  568.     switch (inst->current-inst->max)
  569.     {
  570.     case    GAU_err_busy:
  571.         return( errstr[0]);
  572.     case    GAU_err_notmount:
  573.         return( errstr[1]);
  574.     case    GAU_err_notpresent:
  575.         return( errstr[2]);
  576.     case    GAU_err_unreadable:
  577.         return( errstr[3]);
  578.     case    GAU_err_nodos:
  579.         return( errstr[4]);
  580.     case    GAU_err_notavail:
  581.         return( errstr[5]);
  582.     case    GAU_err_kickstart:
  583.         return( errstr[6]);
  584.         break;
  585.     default:
  586.         return(formattext(inst->current,inst->base,inst->max,inst->txtfmt,inst->voltype,inst->clocktxt));
  587.     }
  588. }
  589.  
  590. ULONG renderGauge(Class *cl,struct Gadget *g,struct gpRender *msg)
  591. {
  592.     struct  RastPort    *rp;
  593.     struct  BitMap      *work_bm;
  594.     struct  RastPort    *wk_rp,*bg_rp,*hs_rp;
  595.     struct  GaugeData   *inst=INST_DATA(cl,g);
  596.     struct  DateStamp   d_stamp;
  597.     WORD                text_x,w,h;
  598.     WORD                x1,x2,g_x,g_size,g_height,t_length;
  599.     char                *fmt;
  600.     LONG                max;
  601.  
  602.     if((msg->MethodID == MY_REFRESH)&&(((struct my_redraw_msg *)msg)->win))
  603.     {
  604.     rp        = ((struct my_redraw_msg *)msg)->win->RPort;
  605.     inst->scr = ((struct my_redraw_msg *)msg)->win->WScreen;
  606.     }
  607.     else if(msg->gpr_GInfo)
  608.     {
  609.     rp = ( msg->MethodID == GM_RENDER ) ? msg->gpr_RPort : (struct RastPort *) ObtainGIRPort(msg->gpr_GInfo);
  610.     inst->scr=msg->gpr_GInfo->gi_Screen;
  611.     }
  612.     if(rp)
  613.     {
  614.     if(inst->InitNotDone)
  615.     {
  616.         for(w=0;w<GAU_UsedColors;w++)GetPenNew(inst->scr,&inst->Colors[w],w,inst->PorC,inst->Pens);
  617.  
  618.         if(work_bm=(struct BitMap *)AllocBitMap(g->Width,g->Height+2,rp->BitMap->Depth,BMF_CLEAR,rp->BitMap))
  619.         {
  620.         if(inst->bg_buffer=(struct RastPort *)pAllocVec(sizeof(struct RastPort)))
  621.         {
  622.             InitRastPort(inst->bg_buffer);
  623.             inst->bg_buffer->BitMap=work_bm;
  624.             my_Blit(rp,g->LeftEdge,g->TopEdge,inst->bg_buffer,0,0,g->Width,g->Height);
  625.             if((!inst->StyleBackground)&&(inst->type==GAU_Type_histmeter))
  626.             {
  627.             SetAPen(rp,inst->Pens[col_bg]);
  628.             RectFill(rp,g->LeftEdge,g->TopEdge,g->LeftEdge+g->Width,g->TopEdge+g->Height);
  629.             SetAPen(inst->bg_buffer,inst->Pens[col_bg]);
  630.             RectFill(inst->bg_buffer,0,0,g->Width,g->Height);
  631.             }
  632.         }
  633.         else
  634.         {
  635.             FreeBitMap(work_bm);
  636.             return(0L);
  637.         }
  638.         }
  639.         else return(0L);
  640.  
  641.         if(work_bm=(struct BitMap *)AllocBitMap(g->Width,g->Height+2,rp->BitMap->Depth,BMF_CLEAR,inst->bg_buffer->BitMap))
  642.         {
  643.         if(inst->wk_buffer=(struct RastPort *)pAllocVec(sizeof(struct RastPort)))
  644.         {
  645.             InitRastPort(inst->wk_buffer);
  646.             inst->wk_buffer->BitMap=work_bm;
  647.  
  648.             inst->text_y=((g->Height-((inst->textFont->tf_Baseline+inst->textFont->tf_YSize)>>1))>>1);
  649.             if(inst->textFont->tf_Baseline<inst->textFont->tf_YSize)
  650.             {
  651.             inst->text_y+=inst->textFont->tf_Baseline-1;
  652.             if(inst->text_y<inst->textFont->tf_Baseline)inst->text_y=inst->textFont->tf_Baseline;
  653.             }
  654.             else
  655.             {
  656.             inst->text_y+=inst->textFont->tf_YSize-1;
  657.             if(inst->text_y<inst->textFont->tf_YSize)   inst->text_y=inst->textFont->tf_YSize;
  658.             }
  659.  
  660.             SetDrMd(inst->wk_buffer,JAM1);
  661.             SetFont(inst->wk_buffer,inst->textFont);
  662.         }
  663.         else
  664.         {
  665.             FreeBitMap(work_bm);
  666.             return(0L);
  667.         }
  668.         }
  669.         else return(0L);
  670.         if(inst->type==GAU_Type_histmeter)
  671.         {
  672.         if(work_bm=(struct BitMap *)AllocBitMap(g->Width,g->Height+2,rp->BitMap->Depth,BMF_CLEAR,inst->wk_buffer->BitMap))
  673.         {
  674.             if(inst->hs_buffer=(struct RastPort *)pAllocVec(sizeof(struct RastPort)))
  675.             {
  676.             inst->histpos=0;
  677.             InitRastPort(inst->hs_buffer);
  678.             inst->hs_buffer->BitMap=work_bm;
  679.             my_Blit(inst->bg_buffer,0,0,inst->hs_buffer,0,0,g->Width,g->Height);
  680.             }
  681.             else
  682.             {
  683.             FreeBitMap(work_bm);
  684.             return(0L);
  685.             }
  686.         }
  687.         else return(0L);
  688.         }
  689.         else inst->hs_buffer=0L;
  690.         inst->old_cur=-1;
  691.         inst->old_bas=-1;
  692.         inst->InitNotDone=FALSE;
  693.     }
  694.  
  695.     wk_rp=inst->wk_buffer;
  696.     bg_rp=inst->bg_buffer;
  697.     switch (inst->type)
  698.     {
  699.         case    GAU_Type_gauge:
  700.             w=g->Width;
  701.             h=g->Height;
  702.             max=inst->max>>8;
  703.             if((inst->current!=inst->old_cur)||(inst->base!=inst->old_bas))
  704.             {
  705.             inst->old_cur=inst->current;
  706.             inst->old_bas=inst->base;
  707.             if(inst->highlight)
  708.             {
  709.                 SetDrMd(rp,JAM1);
  710.                 SetFont(rp,inst->textFont);
  711.                 if(inst->StyleBorder)draw_border_new(rp,inst->labelpos+g->LeftEdge,g->TopEdge,w-inst->labelpos,g->Height,inst->Pens[col_dark],inst->Pens[col_bright]);
  712.                 if(inst->StyleShadowLabel)
  713.                 {
  714.                 SetAPen(rp,inst->Pens[col_dark]);
  715.                 Move(rp,1+g->LeftEdge,inst->text_y+1+g->TopEdge);
  716.                 Text(rp,inst->txtlbl,my_strlen(inst->txtlbl));
  717.                 }
  718.                 SetAPen(rp,inst->Pens[col_label]);
  719.                 Move(rp,g->LeftEdge,inst->text_y+g->TopEdge);
  720.                 Text(rp,inst->txtlbl,my_strlen(inst->txtlbl));
  721.                 inst->highlight=FALSE;
  722.             }
  723.  
  724.             g_x=1+inst->labelpos;
  725.             g_size=w-inst->labelpos-2;
  726.             g_height=h-2;
  727.             my_Blit(bg_rp,g_x,1,wk_rp,g_x,1,g_size,g_height);
  728.  
  729.             if((!inst->StyleNoGauge)&&(inst->current<inst->max))
  730.             {
  731.                 x1=g_size-(WORD)(((inst->base>>8)   *g_size)/((max)==0 ? 1 : (max)));
  732.                 x2=g_size-(WORD)(((inst->current>>8)*g_size)/((max)==0 ? 1 : (max)));
  733.  
  734.                 if(!inst->StyleNoBase)
  735.                 {
  736.                 if(x1<x2)
  737.                 {
  738.                     SetAPen(wk_rp,inst->Pens[col_base]);
  739.                     my_RectFill(wk_rp,g_x,1,x1,g_height);
  740.                     SetAPen(wk_rp,inst->Pens[col_current]);
  741.                     my_RectFill(wk_rp,g_x+x1,1,x2-x1,g_height);
  742.  
  743.                     if(!inst->StyleBackground)
  744.                     {
  745.                     SetAPen(wk_rp,inst->Pens[col_bg]);
  746.                     my_RectFill(wk_rp,g_x+x2,1,g_size-x2,g_height);
  747.                     }
  748.                     if(inst->Style3D)
  749.                     {
  750.                     if(x1>1)   draw_border_new(wk_rp,g_x,1,x1,g_height,inst->Pens[col_bright],inst->Pens[col_dark]);
  751.                     if(x2-x1>1)draw_border_new(wk_rp,g_x+x1,1,x2-x1,g_height,inst->Pens[col_bright],inst->Pens[col_dark]);
  752.                     }
  753.                 }
  754.                 else if(x1>x2)
  755.                 {
  756.                     SetAPen(wk_rp,inst->Pens[col_base]);
  757.                     my_RectFill(wk_rp,g_x,1,x2,g_height);
  758.                     SetAPen(wk_rp,inst->Pens[col_negative]);
  759.                     my_RectFill(wk_rp,g_x+x2,1,x1-x2,g_height);
  760.  
  761.                     if(!inst->StyleBackground)
  762.                     {
  763.                     SetAPen(wk_rp,inst->Pens[col_bg]);
  764.                     my_RectFill(wk_rp,g_x+x1,1,g_size-x1,g_height);
  765.                     }
  766.                     if(inst->Style3D)
  767.                     {
  768.                     if(x2>1)   draw_border_new(wk_rp,g_x,1,x2,g_height,inst->Pens[col_bright],inst->Pens[col_dark]);
  769.                     if(x1-x2>1)draw_border_new(wk_rp,g_x+x2,1,x1-x2,g_height,inst->Pens[col_bright],inst->Pens[col_dark]);
  770.                     }
  771.                 }
  772.                 else
  773.                 {
  774.                     SetAPen(wk_rp,inst->Pens[col_base]);
  775.                     my_RectFill(wk_rp,g_x,1,x1,g_height);
  776.  
  777.                     if(!inst->StyleBackground)
  778.                     {
  779.                     SetAPen(wk_rp,inst->Pens[col_bg]);
  780.                     my_RectFill(wk_rp,g_x+x1,1,g_size-x1,g_height);
  781.                     }
  782.                     if((inst->Style3D)&&(x1>1))draw_border_new(wk_rp,g_x,1,x1,g_height,inst->Pens[col_bright],inst->Pens[col_dark]);
  783.                 }
  784.                 }
  785.                 else
  786.                 {
  787.                 SetAPen(wk_rp,inst->Pens[col_current]);
  788.                 my_RectFill(wk_rp,g_x,1,x2,g_height);
  789.                 if(!inst->StyleBackground)
  790.                 {
  791.                     SetAPen(wk_rp,inst->Pens[col_bg]);
  792.                     my_RectFill(wk_rp,g_x+x2,1,g_size-x2,g_height);
  793.                 }
  794.                 if(inst->Style3D) draw_border_new(wk_rp,g_x,1,x2,g_height,inst->Pens[col_bright],inst->Pens[col_dark]);
  795.                 }
  796.             }
  797.             if(!inst->StyleNoFormat)
  798.             {
  799.                 fmt=getSTR(inst);
  800.                 SetAPen(wk_rp,inst->Pens[col_format]);
  801.                 t_length=TextLength(wk_rp,fmt,my_strlen(fmt));
  802.                 if(t_length<(w-inst->labelpos-1))
  803.                 {
  804.                 switch(inst->fmtind)
  805.                 {
  806.                     case    ind_centered:
  807.                         text_x=g_x+((g_size-t_length)>>1);
  808.                         break;
  809.                     case    ind_left:
  810.                         text_x=g_x+2;
  811.                         break;
  812.                     case    ind_right:
  813.                         text_x=w-t_length-3;
  814.                         break;
  815.                 }
  816.                 Move(wk_rp,text_x,inst->text_y);
  817.                 Text(wk_rp,fmt,my_strlen(fmt));
  818.                 }
  819.             }
  820.             my_Blit(wk_rp,g_x,1,rp,g->LeftEdge+g_x,1+g->TopEdge,g_size,g_height);
  821.             }
  822.             break;
  823.         case    GAU_Type_histmeter:
  824.             max=inst->max>>8;
  825.             w=g->Width;
  826.             h=g->Height;
  827.             g_size=h-1;
  828.             hs_rp=inst->hs_buffer;
  829.             if((!inst->StyleNoGauge)&&(inst->current<inst->max))
  830.             {
  831.             x1=(WORD)(((inst->base   >>8)*(g_size-1))/((max)==0 ? 1 : (max)))+1;
  832.             x2=(WORD)(((inst->current>>8)*(g_size-1))/((max)==0 ? 1 : (max)))+1;
  833.             inst->histpos++;
  834.             if(inst->histpos>w-3)
  835.             {
  836.                 if(inst->StyleBackground)
  837.                 {
  838.                 my_Blit(inst->bg_buffer,0,0,inst->hs_buffer,0,0,w,h);
  839.                 my_Blit(inst->bg_buffer,0,0,rp,g->LeftEdge,g->TopEdge,w,h);
  840.                 }
  841.                 else
  842.                 {
  843.                 SetAPen(hs_rp,inst->Pens[col_bg]);
  844.                 RectFill(hs_rp,0,0,w,h);
  845.                 SetAPen(rp,inst->Pens[col_bg]);
  846.                 RectFill(rp,g->LeftEdge,g->TopEdge,g->LeftEdge+g->Width,g->TopEdge+g->Height);
  847.                 }
  848.                 inst->histpos=0L;
  849.             }
  850.             if(!inst->StyleNoBase)
  851.             {
  852.                 SetAPen(hs_rp,inst->Pens[col_base]);
  853.                 if(x1>x2)
  854.                 {
  855.                 RectFill(hs_rp,inst->histpos,x1,inst->histpos,g_size);
  856.                 SetAPen(hs_rp,inst->Pens[col_current]);
  857.                 RectFill(hs_rp,inst->histpos,x2,inst->histpos,x1);
  858.                 }
  859.                 else if(x1<x2)
  860.                 {
  861.                 RectFill(hs_rp,inst->histpos,x1,inst->histpos,g_size);
  862.                 SetAPen(hs_rp,inst->Pens[col_negative]);
  863.                 RectFill(hs_rp,inst->histpos,x1,inst->histpos,x2);
  864.                 }
  865.                 else
  866.                 {
  867.                 RectFill(hs_rp,inst->histpos,x1,inst->histpos,g_size);
  868.                 }
  869.             }
  870.             else
  871.             {
  872.                 SetAPen(hs_rp,inst->Pens[col_current]);
  873.                 RectFill(hs_rp,inst->histpos,x2,inst->histpos,g_size);
  874.             }
  875.             my_Blit(hs_rp,inst->histpos,0,rp,inst->histpos+g->LeftEdge,g->TopEdge,1,h-1);
  876.             }
  877.             if(inst->StyleBorder)draw_border_new(rp,g->LeftEdge,g->TopEdge,w,h,inst->Pens[col_dark],inst->Pens[col_bright]);
  878.             if(!inst->StyleNoFormat)
  879.             {
  880.             fmt=getSTR(inst);
  881.             SetAPen(wk_rp,inst->Pens[col_format]);
  882.             t_length=TextLength(wk_rp,fmt,my_strlen(fmt));
  883.             if(t_length<w)
  884.             {
  885.                 UWORD x1,x2,y1,y2;
  886.                 switch(inst->fmtind)
  887.                 {
  888.                 case    ind_centered:
  889.                     text_x=((w-t_length)>>1);
  890.                     break;
  891.                 case    ind_left:
  892.                     text_x=2;
  893.                     break;
  894.                 case    ind_right:
  895.                     text_x=w-t_length-2;
  896.                     break;
  897.                 }
  898.                 if((inst->oldlgth>t_length)||(inst->oldx<text_x))
  899.                 {
  900.                 x1=inst->oldx;
  901.                 x2=inst->oldlgth;
  902.                 }
  903.                 else
  904.                 {
  905.                 x1=text_x;
  906.                 x2=t_length;
  907.                 }
  908.                 y1=h-1-inst->textFont->tf_YSize;
  909.                 y2=inst->textFont->tf_YSize;
  910.                 if((x1>0)&&((y1)>0)&&((x1+x2)<w))
  911.                 {
  912.                 my_Blit(hs_rp,x1,y1,wk_rp,x1,            y1,           x2,y2);
  913.                 Move(wk_rp,text_x,h-3);
  914.                 Text(wk_rp,fmt,my_strlen(fmt));
  915.                 my_Blit(wk_rp,x1,y1,rp,   x1+g->LeftEdge,y1+g->TopEdge,x2,y2);
  916.                 }
  917.                 inst->oldlgth=t_length;
  918.                 inst->oldx=text_x;
  919.             }
  920.             }
  921.             break;
  922.         case    GAU_Type_clock:
  923.             if(inst->clocktxt)
  924.             {
  925.             w=g->Width-1;
  926.             h=g->Height;
  927.             DateStamp((struct DateStamp *)&d_stamp);
  928.             inst->clockpos=0; putCharHook.h_Data=inst; FormatDate(inst->locale,inst->txtfmt,&d_stamp,&putCharHook);
  929.             if((t_length=TextLength(wk_rp,inst->clocktxt,my_strlen(inst->clocktxt)))<w)
  930.             {
  931.                 switch(inst->fmtind)
  932.                 {
  933.                 case    ind_centered:
  934.                     text_x=(w-t_length)>>1;
  935.                     break;
  936.                 case    ind_left:
  937.                     text_x=0;
  938.                     break;
  939.                 case    ind_right:
  940.                     text_x=w-t_length-1;
  941.                     break;
  942.                 }
  943.                 if(inst->oldclockw>t_length)
  944.                 {
  945.                 my_Blit(bg_rp,inst->oldclockx,0,wk_rp,inst->oldclockx,0,inst->oldclockw,h);
  946.                 }
  947.                 else
  948.                 {
  949.                 my_Blit(bg_rp,text_x,0,wk_rp,text_x,0,t_length,h);
  950.                 }
  951.                 if(inst->StyleShadowLabel)
  952.                 {
  953.                 SetAPen(wk_rp,inst->Pens[col_dark]);
  954.                 Move(wk_rp,text_x+1,inst->text_y+1);
  955.                 Text(wk_rp,inst->clocktxt,my_strlen(inst->clocktxt));
  956.                 }
  957.                 SetAPen(wk_rp,inst->Pens[col_format]);
  958.                 Move(wk_rp,text_x,inst->text_y);
  959.                 Text(wk_rp,inst->clocktxt,my_strlen(inst->clocktxt));
  960.                 if(inst->oldclockw>t_length)
  961.                 {
  962.                 my_Blit(wk_rp,inst->oldclockx,0,rp,g->LeftEdge+inst->oldclockx,g->TopEdge,inst->oldclockw,h);
  963.                 }
  964.                 else
  965.                 {
  966.                 my_Blit(wk_rp,text_x,0,rp,g->LeftEdge+text_x,g->TopEdge,t_length,h);
  967.                 }
  968.                 inst->oldclockx=text_x;
  969.                 inst->oldclockw=t_length;
  970.             }
  971.             }
  972.             break;
  973.     }
  974.     if((msg->MethodID !=GM_RENDER)&&(msg->MethodID !=MY_REFRESH))ReleaseGIRPort(rp);
  975.     return(TRUE);
  976.     }
  977.     else return(FALSE);
  978. }
  979.  
  980.